#ifndef TASKS_H
#define TASKS_H

#include <defs/global.h>
#include <QtCore>
#include <core/task.h>
#include <core/entityobject.h>

namespace Optra {

    class TaskEntry : public Opl::Core::EntityObject
    {
        Q_OBJECT
        Q_PROPERTY(QString name READ name NOTIFY nameChanged)
        Q_PROPERTY(Opl::Core::Task* task READ task)
    public:
        QString name() { return _name; }
        Opl::Core::Task* task() { return _task; }
        bool autodelete() { return _autodelete; }

        TaskEntry():
            _autodelete(true)
        {

        }

        TaskEntry(const QString& n, Opl::Core::Task* t, bool autodel):
            _name(n)
          ,_task(t)
          ,_autodelete(autodel)
        {

        }
    signals:
        void nameChanged();

    private:
        Opl::Core::Task* _task;
        QString _name;
        bool _autodelete;
    };


    O_PRIVATE_DECLARE(TasksController);
    class TasksController : public Opl::Core::EntityObject
    {
        Q_OBJECT
    public:

        TasksController(Opl::Core::EntityObject *parent);
        ~TasksController();

        bool start(Opl::Core::Task* task, QString name = QString());
        bool start(Opl::Core::Task* task, bool autodelete, QString name = QString());

    public slots:
        void stop(const Opl::Core::Entity::EntityId& uuid);
        void stopAll();

    signals:

        void taskStarted(Opl::Core::Entity::EntityId uuid);
        void taskFinished(Opl::Core::Entity::EntityId uuid);

        void tasksChanged();

    private slots:
        void taskDone();
    private:
        O_PRIVATE_DECLARE_MEMBER(TasksController)
    };

}

#endif // TASKS_H


